import 'package:core_package/core_package.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app_unionad/core/configuration.dart';
import 'package:flutter_app_unionad/model/promotion_materials_model.dart';
import 'package:flutter_app_unionad/router/routes.dart';
import 'package:flutter_app_unionad/ui/basice/my_button.dart';

class ShowPromotionAdWidget extends StatefulWidget {
  final PromotionMaterialsModel model;

  const ShowPromotionAdWidget(this.model, {Key? key}) : super(key: key);

  @override
  _ShowPromotionAdWidgetState createState() => _ShowPromotionAdWidgetState();
}

class _ShowPromotionAdWidgetState extends State<ShowPromotionAdWidget> {
  bool select = false;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Expanded(
          child: Container(
            decoration: BoxDecoration(
              color: Colors.white,
            ),
            width: double.infinity,
            child: Column(
              children: [
                Expanded(
                  child: SingleChildScrollView(
                    child: GestureDetector(
                      onTap: () {
                        if (widget.model.link != null) {
                          gotoApp(context, route: widget.model.link!, isSplash: false);
                        }
                      },
                      child: ShowPicWidget(
                        widget.model.coverImg ?? '',
                        width: double.infinity,
                        fit: BoxFit.fitWidth,
                        showDefault: false,
                      ),
                    ),
                  ),
                ),
                SizedBox(height: 10.px),
                GestureDetector(
                  onTap: () {
                    setState(() {
                      select = !select;
                    });
                  },
                  child: Row(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Icon(
                        Icons.check_circle,
                        color: select ? MyColors.color_245_174_41 : Colors.black12,
                        size: 15.px,
                      ),
                      SizedBox(
                        width: 5.px,
                      ),
                      Text(
                        '三十天不再提示',
                        style: TextStyle(color: Colors.black87, fontSize: 12.px),
                      ),
                    ],
                  ),
                ),
                SizedBox(height: 10.px),
              ],
            ),
          ),
        ),
        SizedBox(height: 55.px),
        MyButton(
          title: '关闭',
          onTap: () {
            if (select) {
              UserCacheUil.setInt(Configuration.adTime, DateTime.now().millisecondsSinceEpoch);
              UserCacheUil.setString(Configuration.adUrl, widget.model.coverImg ?? '');
            }
            Navigator.pop(context);
          },
        ),
      ],
    );
  }
}
